home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 9.7 KB | 332 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWViewAs.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWVIEWAS_H
- #include "FWViewAs.h"
- #endif
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWPOLY_H
- #include "FWPoly.h"
- #endif
-
- #ifndef FWPOLYSH_H
- #include "FWPolySh.h"
- #endif
-
- #ifndef FWREGION_H
- #include "FWRegion.h"
- #endif
-
- #ifndef FWBMPSHP_H
- #include "FWBmpShp.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWICONSH_H
- #include "FWIconSh.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__ICONS__)
- #include <Icons.h>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwpart2
- #endif
-
- //========================================================================================
- // CLASS FW_CViewAs
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::FW_CViewAs
- //----------------------------------------------------------------------------------------
-
- FW_CViewAs::FW_CViewAs(Environment *ev, FW_CPart* part) :
- fPart(part),
- fShape(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::~FW_CViewAs
- //----------------------------------------------------------------------------------------
-
- FW_CViewAs::~FW_CViewAs()
- {
- delete fShape;
- fShape = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAs::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CViewAs::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- FW_ASSERT(fShape);
-
- FW_CFacetContext fc(ev, facet, invalidShape);
- fShape->Render(fc);
- }
-
- //========================================================================================
- // CLASS FW_CViewAsThumbnail
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsThumbnail::FW_CViewAsThumbnail
- //----------------------------------------------------------------------------------------
-
- FW_CViewAsThumbnail::FW_CViewAsThumbnail(Environment *ev, FW_CPart* part) :
- FW_CViewAs(ev, part)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsThumbnail::~FW_CViewAsThumbnail
- //----------------------------------------------------------------------------------------
-
- FW_CViewAsThumbnail::~FW_CViewAsThumbnail()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsThumbnail::RenderThumbnailFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CViewAsThumbnail::RenderThumbnailFrame(Environment* ev, FW_CGraphicContext& gc)
- {
- FW_CPoint flap[3] =
- {
- FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(16)),
- FW_CPoint(FW_IntToFixed(32), FW_IntToFixed( 0)),
- FW_CPoint(FW_IntToFixed(32), FW_IntToFixed(16))
- };
-
- FW_PPolygon polygon2(3, flap);
- FW_CPolygonShape::RenderPolygon(gc, polygon2, FW_kFill, FALSE, FW_kRGBLightGray);
-
- FW_CPoint thumbnailContour[8] =
- {
- FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(16)),
- FW_CPoint(FW_IntToFixed(32), FW_IntToFixed( 0)),
- FW_CPoint(FW_IntToFixed( 0), FW_IntToFixed( 0)),
- FW_CPoint(FW_IntToFixed( 0), FW_IntToFixed(63)),
- FW_CPoint(FW_IntToFixed(47), FW_IntToFixed(63)),
- FW_CPoint(FW_IntToFixed(47), FW_IntToFixed(16)),
- FW_CPoint(FW_IntToFixed(32), FW_IntToFixed(16)),
- FW_CPoint(FW_IntToFixed(32), FW_IntToFixed( 0))
- };
-
- FW_PPolygon polygon(8, thumbnailContour);
- FW_CPolygonShape::RenderPolygon(gc, polygon, FW_kFrame, FALSE);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsThumbnail::Load
- //----------------------------------------------------------------------------------------
-
- void FW_CViewAsThumbnail::Load(Environment* ev, FW_CFrame* frame)
- {
- if (fShape == NULL)
- {
- FW_CRect rect(FW_kZeroPoint, FW_IntToFixed(48), FW_IntToFixed(64));
-
- FW_PBitmap bitmap(48, 64, 8);
-
- {
- FW_CBitmapContext bc(ev, bitmap);
- FW_CRectShape::RenderRect(bc, rect, FW_kFill, FW_kWhiteEraseInk);
-
- frame->BuildThumbnail(ev, bc, rect);
- RenderThumbnailFrame(ev, bc);
- }
-
- fShape = FW_NEW(FW_CBitmapShape, (bitmap, rect));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsThumbnail::CalcUsedShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CViewAsThumbnail::CalcUsedShape(Environment* ev) const
- {
- FW_CPoint thumbnailContour[6] =
- {
- FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(16)),
- FW_CPoint(FW_IntToFixed(32), FW_IntToFixed( 0)),
- FW_CPoint(FW_IntToFixed( 0), FW_IntToFixed( 0)),
- FW_CPoint(FW_IntToFixed( 0), FW_IntToFixed(64)),
- FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(64)),
- FW_CPoint(FW_IntToFixed(48), FW_IntToFixed(16))
- };
-
- ODRgnHandle rgnHandle = FW_CreatePolygonRegion(6, thumbnailContour);
-
- return ::FW_NewODShape(ev, rgnHandle);
- }
-
- //========================================================================================
- // CLASS FW_CViewAsIcon
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsIcon::FW_CViewAsIcon
- //----------------------------------------------------------------------------------------
-
- FW_CViewAsIcon::FW_CViewAsIcon(Environment *ev, FW_CPart* part, short iconSize) :
- FW_CViewAs(ev, part),
- fIconSize(iconSize)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsIcon::~FW_CViewAsIcon
- //----------------------------------------------------------------------------------------
-
- FW_CViewAsIcon::~FW_CViewAsIcon()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsIcon::LoadIcon
- //----------------------------------------------------------------------------------------
-
- void FW_CViewAsIcon::Load(Environment* ev, FW_CFrame* frame)
- {
- if (fShape == NULL)
- {
- FW_CSharedLibraryResourceFile resourceFile(fPart->GetPartInstance(ev));
- FW_PIcon icon(resourceFile, fPart->GetIconID(ev), fIconSize);
-
- FW_CRect iconRect(FW_kZeroPoint, FW_IntToFixed(fIconSize), FW_IntToFixed(fIconSize));
- fShape = FW_NEW(FW_CIconShape, (icon, iconRect, FW_kIconAlignLeft | FW_kIconAlignTop));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsIcon::CalcUsedShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CViewAsIcon::CalcUsedShape(Environment* ev) const
- {
- FW_ASSERT(fShape != NULL);
-
- #ifdef FW_BUILD_MAC
- FW_PIcon icon;
- FW_RenderIconOptions options;
- FW_CRect rect;
- ((FW_CIconShape*)fShape)->GetGeometry(icon, options, rect);
-
- FW_PlatformIcon platformIcon = icon->GetPlatformIcon();
-
- RgnHandle rgn = ::NewRgn();
- FW_SPlatformRect bounds(0, 0, fIconSize, fIconSize);
- ::IconSuiteToRgn(rgn, &bounds, atNone, platformIcon);
-
- return ::FW_NewODShape(ev, rgn);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("Not yet implemented");
- #endif
- }
-
- //========================================================================================
- // CLASS FW_CViewAsSmallIcon
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsSmallIcon::FW_CViewAsSmallIcon
- //----------------------------------------------------------------------------------------
-
- FW_CViewAsSmallIcon::FW_CViewAsSmallIcon(Environment *ev, FW_CPart* part) :
- FW_CViewAsIcon(ev, part, 16)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsSmallIcon::~FW_CViewAsSmallIcon
- //----------------------------------------------------------------------------------------
-
- FW_CViewAsSmallIcon::~FW_CViewAsSmallIcon()
- {
- }
-
- //========================================================================================
- // CLASS FW_CViewAsLargeIcon
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsLargeIcon::FW_CViewAsLargeIcon
- //----------------------------------------------------------------------------------------
-
- FW_CViewAsLargeIcon::FW_CViewAsLargeIcon(Environment *ev, FW_CPart* part) :
- FW_CViewAsIcon(ev, part, 32)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewAsLargeIcon::~FW_CViewAsLargeIcon
- //----------------------------------------------------------------------------------------
-
- FW_CViewAsLargeIcon::~FW_CViewAsLargeIcon()
- {
- }
-
-